using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace LogFileViewer
{
    public abstract class LogfileAccess
    {
        protected LogfileAccess(FileStream str)
        {
            this.fileStream = str;
            this.streamReader = new StreamReader(str, Encoding.Default);
        }

        protected LogfileAccess(Dictionary<MessageTypes, List<LogEntry>> data, string filename)
        {
            this.data = data;
            this.fileStream = File.OpenRead(filename);
            this.streamReader = new StreamReader(this.fileStream, Encoding.Default);
        }

        Properties.Settings sets = Properties.Settings.Default;

        protected Dictionary<MessageTypes, List<LogEntry>> data;

        protected FileStream fileStream;
        protected StreamReader streamReader;

        protected void startProcess(string infoText)
        {
            // Set progress bar etc

            // GUI STUFF
            //loadFileProgressBar.Visible = true;
            //lblProgressInfo.Text = infoText;
            //lblProgressInfo.Visible = true;
            //double dividor = mainWind.getProgressBarDividor(str);
        }

        protected void incrementProgressBar()
        {
            // GUI STUFF
            //if (tempLine != null)
            //{
            //    mainWind.incrementProgressBar(dividor, found);
            //}
        }

        protected void stopProcess()
        {
            // Reset progress bar etc
        }

        protected void closeStreams()
        {
            if (fileStream != null)
            {
                fileStream.Unlock(0, fileStream.Length);
                if (streamReader != null)
                {
                    streamReader.Close();
                    streamReader.Dispose();
                }
                fileStream.Close();
                fileStream.Dispose();
            }
        }
    }
}
